package com.yonyou.byb.bs;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.bd.supplier.SupplierVO;
import nc.vo.fi.pub.SqlUtils;
import nc.vo.fibd.RecpaytypeVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;

@SuppressWarnings("unchecked")
public class DataUtils {
	
	public static Map<String,? extends SuperVO> getData(List<String> ids,Class voclass,String attr) {
		return getData(ids.toArray(new String[0]),voclass,attr);
	}
	
	public static Map<String,? extends SuperVO> getData(String[] ids,Class voclass,String attr) {
		Map<String,SuperVO> map = new HashMap<String,SuperVO>();
		IUAPQueryBS query = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		try {
			Collection<? extends SuperVO> list = query.retrieveByClause(voclass, SqlUtils.getInStr(attr, ids, false));
			for(SuperVO vo: list) {
				map.put(vo.getAttributeValue(attr).toString(), vo);
			}
		} catch (BusinessException e) {
			Logger.error(e.getMessage(), e);
		}
		
		return map;
	}
	

	public static Map<String,DefdocVO> getPeiSongState() {
		Map<String,DefdocVO> map = new HashMap<String,DefdocVO>();
		IUAPQueryBS query = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		try {
			String sql = " pk_defdoclist = (select pk_defdoclist from bd_defdoclist where code='BYB01')";
			Collection<DefdocVO> list = query.retrieveByClause(DefdocVO.class, sql);
			for(DefdocVO vo: list) {
				map.put(vo.getCode(), vo);
			}
		} catch (BusinessException e) {
			Logger.error(e.getMessage(), e);
		}
		
		return map;
	}
	
	public static String getRelatedSupplier(String pkOrg) {
		String pkSupplier = null;
		String sql = "select c.pk_supplier from bd_supplier c " +
				"inner join org_financeorg b on c.pk_financeorg = b.pk_financeorg " +
				"where b.code='"+ pkOrg +"' and c.dr=0";
		try {
			List<SupplierVO> col = (List<SupplierVO>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sql, new BeanListProcessor(SupplierVO.class));
			if(col != null) {
				pkSupplier = col.get(0).getPk_supplier();
			}
		} catch (Exception e) {
			Logger.error(e.getMessage());
		}
		return pkSupplier;
	}
	
	public static Map<String,String> getARAPType() {
		Map<String,String> map = new HashMap<>();
		
		String sql = " dr=0";
		
		try {
			List<RecpaytypeVO> col = (List<RecpaytypeVO>) NCLocator.getInstance().lookup(IUAPQueryBS.class).retrieveByClause(RecpaytypeVO.class, sql);
			if(col != null && !col.isEmpty()) {
				for(RecpaytypeVO vo : col) {
					map.put(vo.getCode(), vo.getPk_recpaytype());
				}
			}
		} catch (Exception e) {
			Logger.error(e.getMessage());
		}
		
		return map;
	}

	
	
	

}
